Object Oriented Programming
(Your comments/questions/suggestions are
invited. Please e-mail me)
Introduction
Object oriented programming is
something that was waiting to happen. Since time immemorial programmers have been writing
lines upon lines of code without much thought or plan. This was alright when software
applications were simple and limited to a few hundred lines of code. As time went on,
computerization of business processes became more and more common place. The business
requirements started becoming more and more complex. Gone are the days when a manager
would tell his team, "OK folks I need a program to remind me about my daily
tasks". Today a Vice President of the company would say something like, "We need
a tool to keep track of our sales all around the world. This tool should allow for
disaster recovery, trend analysis, charting and blah, blah, blah...". The founders of
Object Oriented Programming ( OOP ) realized that to create complex software applications,
a change in the programming paradigm was required. To evolve this OOP paradigm they looked
at real life. To better understand the need for a new software paradigm let us
start with a simple example. One fine evening you walk down to the friendly electrical store and buy a brand new toaster Model 101 made by Coyote Inc.. You love the shining steel exterior and the smooth soundless motion of the push-down lever. You wake up an hour earlier the next morning because you cannot wait to eat your buttered toast with coffee. You plug in the toaster, pop in two slices of bread and push down the lever. Five minutes ... nothing happens. You peep down into the slot but do not even see the red glowing filament. You are furious. As soon as the store opens you take the defective toaster back for a replacement. The salesman says to you "Ah! Ha!... you forgot to activate the small 'enable' lever at the bottom. If you had read the manual you would have realized it". You slink back home thinking "Who reads through a toaster manual anyway. A toaster is a toaster". You just hit on the concept of consistent user interface (more about that later). This was just a hypothetical
example. In real life you will rarely face such a problem with a toaster. Today you could
go a store and buy any toaster on the shelves and not miss your morning
breakfast just because you did not read the manual. The same applies to a car or an alarm
clock ( not VCRs though In real life, therefore, most of the time we are able to get our world going without much of a problem. If you spend the night at a remote hotel, you generally do not need to call the receptionist to tell you how to set the alarm in the alarm clock in your room. You may struggle with it a little bit, if you have never seen that model before, but ultimately you will figure out how to set an alarm. Before the advent of OOP, software developers faced the same problem that you faced with the off-beat toaster. Note the first word in OOP. It is 'object'. And, indeed, 'object' here refers to nothing other than the kind of objects that we encounter in real life (like toasters and cars and wash basins). OOP is a programming paradigm that works with 'objects' rather than with just FORTRAN or C language code. With that, let us move on to the key concepts of Object Oriented Programming. Since I primarily wrote this tutorial for the layman, I don't want to give examples using actual code. Rather I will try to explain the concepts by giving examples from real life. But, remember, OOP really applies to an actual programmer who writes code ( remember the 'P' in OOP stands for 'programming') If you are a programmer then you could go to the
several scattered 'programmer notes' that appear throughout the tutorial. These programmer
notes are shown using the graphic The main concepts in Object Oriented Programming As mentioned earlier, OOP addresses real life. Memorize that magic sentence and you will have understood the essence of OOP. Before OOP came, software was far from real life. The founding fathers of OOP did not just wake up one day and start defining high sounding terms like Encapsulation and Polymorphism to ensure themselves a job. They just looked at real life and analyzed its properties and tried to invent a new programming paradigm based on real life. The terms that you will be reading about in the following sections are just situations from real life. You never knew them by those names, but these properties existed in a 'taken for granted' manner. So be not afraid of those high sounding terms, you know them already. Here we are only trying to learn how 'real life' is being implemented in software. The C++ language is to OOP as the Boeing 747 Jumbo is to civil aviation. The C++ language dominates the OOP scene. Not until the advent of the Java programming language has any language attained the popularity of C++ in the OOP arena. The inventor of C++ is Bjarne Stroustrup of AT&T Labs. The C++ language has many defects but they are deliberate. When C++ was invented, business sense prevailed and the folks at AT&T thought that if the new language was made too restrictive, programmers will not move away from the most popular language of all time - C. So they kept some of the features of the C language like pointers, global variables and the nasty goto statement. To quote Stroustrup himself "The C++ language access control mechanisms provide protection against accident - not against fraud". The Java language has gone one-up on C++ in this regard. It is a truly object oriented language. In this tutorial we will deal only with C++. Let us jump into the bricks and mortar of Object Oriented Programming. Click on the links below to proceed.
|